﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VehicleTransactionFilter.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="Hisaab.Data.Filters.VehicleTransactionFilter" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Filters
{
    using System.Data.Objects;
    using System.Linq;
    using Entities;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Filters.VehicleTransactionFilter"/> type.
    /// </summary>
    public static class VehicleTransactionFilter
    {
        /// <summary>
        /// Filters the specified VehicleTransaction collection.
        /// </summary>
        /// <param name="collection">The VehicleTransaction collection.</param>
        /// <param name="objectToMatch">The VehicleTransaction to match.</param>
        /// <returns>List of filtered VehicleTransactions</returns>
        public static IQueryable<VehicleTransaction> Filter(this IObjectSet<VehicleTransaction> collection, VehicleTransaction objectToMatch)
        {
            return objectToMatch == null ?
                collection :
                from vt in collection
                where (objectToMatch.Id == 0 || vt.Id == objectToMatch.Id) &&
                    (objectToMatch.TransactionId == 0 || vt.TransactionId == objectToMatch.TransactionId) &&
                    (objectToMatch.VehicleId == 0 || vt.VehicleId == objectToMatch.VehicleId) &&
                    (objectToMatch.Milage == 0 || vt.Milage == objectToMatch.Milage) &&
                    (!objectToMatch.Fill.HasValue || vt.Fill.Value == objectToMatch.Fill.Value) &&
                    (!objectToMatch.Service.HasValue || vt.Service.Value == objectToMatch.Service.Value) &&
                    (!objectToMatch.Oil.HasValue || vt.Oil.Value == objectToMatch.Oil.Value) &&
                    (!objectToMatch.Tires.HasValue || vt.Tires.Value == objectToMatch.Tires.Value) &&
                    (!objectToMatch.Fuel.HasValue || vt.Fuel.Value == objectToMatch.Fuel.Value)
                select vt;
        }
    }
}